package tree.test108;

import listbyorder.utils.TreeNode;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/16 12:58
 */
public class Solution1 {

    public TreeNode sortedArrayToBST(int[] nums) {
        if (nums == null || nums.length == 0) return null;
        return bs(nums, 0, nums.length - 1);
    }

    private TreeNode bs(int[] nums, int l, int r) {
        if (l > r) return null;
        int m = (l + r) >> 1;
        TreeNode root = new TreeNode(nums[m]);
        root.left = bs(nums, l, m - 1);
        root.right = bs(nums, m + 1, r);
        return root;
    }
}
